package recite.word.client.controller;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import recite.word.client.dto.file.SendMessageDTO;
import recite.word.client.dto.file.TranslateDTO;
import recite.word.client.service.IFileService;
import recite.word.service.base.common.request.BaseRequest;
import recite.word.service.base.common.response.ResponseResult;

import java.io.IOException;

@RestController
@RequestMapping("/client/file")
@Api(tags = "客户端【文件操作】controller")
public class FileController {

    @Autowired
    private IFileService fileService;

    /**
     * 上传文件到腾讯云
     */
    @PostMapping(value = "upload", consumes = "multipart/form-data")
    public ResponseResult<String> imgUpload(MultipartFile file) throws IOException {
        String url = fileService.imgUpload(file);
        return ResponseResult.success(url);
    }

    /**
     * 图片识别 传一个图片和语言（eng/chi_sim）
     */
    @PostMapping("/tess4J")
    public ResponseResult<String> Tess4J(MultipartFile file,String language) throws Exception {
        String result = fileService.Tess4J(file, language);
        return ResponseResult.success(result);
    }

    /**
     * 阿里云文字翻译 en->zh
     */
    @PostMapping("/translate")
    public ResponseResult<String> translate(@RequestBody BaseRequest<TranslateDTO> dto) {
        String translate = fileService.translate(dto);
        return ResponseResult.success(translate);
    }

    /**
     * 阿里云发送短信  1:注册  2:忘记密码
     */
    @PostMapping("/sendMessage")
    public ResponseResult sendMessage(@RequestBody BaseRequest<SendMessageDTO> dto) {
        fileService.sendMessage(dto);
        return ResponseResult.success();
    }

}
